# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Cookie Engineer <cookiengineer@protonmail.ch>

pkgname=('dark-reader' 'firefox-dark-reader' 'thunderbird-dark-reader')
pkgbase=dark-reader
pkgver=4.9.63
pkgrel=1
pkgdesc='Inverts brightness of web pages and aims to reduce eyestrain while browsing the web'
arch=('any')
url=https://darkreader.org/
license=('MIT')
makedepends=('npm')
source=("https://github.com/darkreader/darkreader/archive/v$pkgver/darkreader-$pkgver.tar.gz")
b2sums=('c8ee23f27bf12567c16381f0fa38d974ea9233ad677fcdb88b3a7613e849d3e103db53eb7861190a237322893f6ef7e9f5a63ce3f364d128ce32deb0acfecaee')

prepare() {
  cd darkreader-$pkgver
#  npm config set registry https://registry.loongnix.cn:5873/
  npm ci
}

build() {
  cd darkreader-$pkgver
  npm run build
}

check() {
  cd darkreader-$pkgver
  npm test
}

package_dark-reader() {
  pkgdesc+=' (unpacked webextension)'
  cd darkreader-$pkgver/build/release/chrome
  install -d "$pkgdir"/usr/lib/$pkgbase
  cp -r -- * "$pkgdir"/usr/lib/$pkgbase
}

package_firefox-dark-reader() {
  groups=('firefox-addons')
  cd darkreader-$pkgver/build/release
  install -Dm644 darkreader-firefox.xpi \
    "$pkgdir"/usr/lib/firefox/browser/extensions/addon@darkreader.org.xpi
}

package_thunderbird-dark-reader() {
  cd darkreader-$pkgver/build/release
  install -Dm644 darkreader-thunderbird.xpi \
    "$pkgdir"/usr/lib/thunderbird/extensions/addon@darkreader.org.xpi
}
